#include<bits/stdc++.h>
using namespace std;
const int MAXN=150010;
int n,ans,now;
struct node
{
	int a,b;
	bool operator<(const node x)const
	{
		return b<x.b;
	}
}a[MAXN];
priority_queue<int>q;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d%d",&a[i].a,&a[i].b);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i)
	{
		int x=a[i].a,y=a[i].b;
		if(x+now<=y)
		{
			++ans;
			now+=x;
			q.push(x);
		}
		else
		{
			if(q.empty())continue;
			int t=q.top();
			if(t>x&&now-t+x<=y)
			{
				q.pop();
				q.push(x);
				now=now-t+x;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}
